package com.ssm.config;

import com.ssm.interceptor.JwtAuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类
 * 【SpringMVC: 配置类】
 * 实现WebMvcConfigurer接口，配置MVC相关功能
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * JWT认证拦截器
     * 【Spring: IOC依赖注入】
     */
    @Autowired
    private JwtAuthInterceptor jwtAuthInterceptor;

    /**
     * 添加拦截器
     * 【SpringMVC: 拦截器配置】
     * 配置拦截器的拦截路径和排除路径
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtAuthInterceptor)
                .addPathPatterns("/api/**")  // 拦截所有/api/开头的请求
                .excludePathPatterns("/api/auth/login", "/api/auth/register"); // 排除登录和注册接口
    }
} 